<extend name="Cart/cart" />

<block name="main">
<div class="page-main">
    <div class="container">
        <div id="J_cartBox" class="">
       

                    <div class="cart-goods-list">
                <div class="list-head clearfix">
                    <!-- <div class="col col-check"><i class="iconfont icon-checkbox icon-checkbox-selected" id="J_selectAll">√</i>全选</div> -->
                    <div class="col col-img">&nbsp;</div>
                    <div class="col col-name">商品名称</div>
                    <div class="col col-price">单价</div>
                    <div class="col col-num">数量</div>
                    <div class="col col-total">小计</div>
                    <div class="col col-action">操作</div>
                </div>
       
                <div class="list-body" id="J_cartListBody">
                      <foreach name='data' item='val'>   
                    <div class="item-box"> 
                        <div class="item-table J_cartGoods"> 
                            <div class="item-row clearfix"> 
                                <div class="col col-check">  
                                    <!-- <i class="iconfont icon-checkbox icon-checkbox-selected J_itemCheckbox">√</i>   -->
                                </div> 
                                <div class="col col-img">  
                                    <a href="" target="_blank"> <img alt="" src="__PUBLIC__/Uploads/<{$val.logo}>" width="80" height="80"> </a>  
                                </div> 
                                <div class="col col-name">  
                                    <div class="tags"></div>  
                                        <h3 class="name"><a href="" target="_blank"> <{$val.prodectsname}> </a></h3>      
                                    </div> 
                                    <div class="col col-price">  <{$val.price}>元 </div> 
                                    <div class="col col-num">
                                    <div class="change-goods-num clearfix J_changeGoodsNum"> 
                                    <a href="#" class="J_minus" data-sku='<{$val.sku_id}>' data-max='<{$val.max_id}>'><i class="iconfont"  ></i>
                                    </a> 
                                    <input type="text" name="num" value="<{$val.anum}>" class="goods-num J_goodsNum" readonly > 

                                    <a href="#" class="J_plus"  data-sku = '<{$val.sku_id}>'  data-max = "<{$val.max_id}>"><i class="iconfont" ></i>
                                    </a>

                                    </div>  
                                </div> 
                                <div class="col col-total"><?php echo ($val['price']*$val['anum']); ?><p class="pre-info">  </p> </div> 

                                <div class="col col-action"> <a id="" href="#" class="del J_delGoods" data-sku='<{$val.sku_id}>' data-max='<{$val.max_id}>'>
                                    <i class="iconfont"></i></a> 
                                </div>
                            </div> 
                        </div>        
                    </div>   
                    </foreach>   
               </div>             
            </div>

           
            <div class="cart-bar clearfix" id="J_cartBar">
                <div class="section-left">
                    <a href="<{:U('Home/index/index')}>" class="back-shopping J_goShoping">继续购物</a>
                    <span class="cart-total">共 <i id="J_cartTotalNum">  <{$count}></i> 件商品
                    <!-- 已选择 <i id="J_selTotalNum">1</i> 件</span> -->

                </div>
                <span class="activity-money hide">
                  <!--   活动优惠：减 <i id="J_cartActivityMoney">0</i> 元 -->
                </span>
                <span class="total-price">
                    合计（不含运费）：<em id="J_cartTotalPrice">
                        <{$totalprice}>
                    </em>元
                </span>
                <a href="<{:U('Home/Fillorder/index')}>" class="btn btn-a btn btn-primary" id="J_goCheckout">去结算</a>
            </div>
        </div>
    </div>
</div>


<script src="__PUBLIC__/Compoent/XQ/js/jquery-1.8.2.js"></script> 

<script>

   //数量加
    
    $('.J_plus').click(function(){

    var sku        = $(this).data('sku');

    var max        = $(this).data('max');    


    var anum       = parseInt($(this).prev().val());
    
    $('#J_cartTotalPrice').html();


    if (anum ===NaN || anum === undefined) {

        alert('请输入正确的数量');
    }else{

    var num =  anum+1;
        
    }
   
            $.ajax({
               type: "POST",
               url: "<{:U('Home/cart/updateNum')}>",
               data: {'num':num,'sku':sku,'max':max},
               async:false,
               success: function(msg){

                if (msg==0) {

                    alert('网络错误，稍后再试');

                }
            
               window.location.reload();
       }
    });

            return false;
    })



    //数量减少


    $('.J_minus').click(function(){

    var sku        = $(this).data('sku');

    var max        = $(this).data('max');    


    var anum       = parseInt($(this).next().val());


    if (anum ===NaN || anum === undefined) {

        alert('请输入正确的数量');
    }else{



       num = anum-1;
  
        
    }
   
            $.ajax({
               type: "POST",
               url: "<{:U('Home/cart/updateNum')}>",
               data: {'num':num,'sku':sku,'max':max},
               async:false,
               success: function(msg){
            
               window.location.reload();
       }
    });

            return false;
    })

//删除

    $('.del').click(function(){

        var sku        = $(this).data('sku');

        var that       = $(this);

            $.ajax({
               type: "POST",
               url: "<{:U('Home/cart/deleteGoods')}>",
               data: {'sku':sku},
               async:false,
               success: function(msg){

                if(msg==1){

                    that.parent().remove();
                }else{

                    alert('服务器正忙，稍后再试');
                }
            
               window.location.reload();
       }
    });

            return false;
        

    })






</script>

</block>